/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * msnCrearCuenta.java
 *
 * Created on 31/08/2011, 02:50:34 PM
 */
package UI;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import msnclient.Controladora;

/**
 *
 * @author Agustin
 */
public class msnCrearCuenta extends javax.swing.JFrame {

    /** Creates new form msnCrearCuenta */
    public msnCrearCuenta() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTitulo = new javax.swing.JLabel();
        lblCrearCuenta = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtNombreUsuario = new javax.swing.JTextPane();
        separadorEstado = new javax.swing.JSeparator();
        BarraEstado = new javax.swing.JTextField();
        lblNombreUsuario = new javax.swing.JLabel();
        lblContraseña = new javax.swing.JLabel();
        txtContraseña = new javax.swing.JPasswordField();
        txtContraseñare = new javax.swing.JPasswordField();
        lblContraseñaRE = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lblDominio = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        lblTitulo.setFont(new java.awt.Font("Tw Cen MT", 0, 48)); // NOI18N
        lblTitulo.setText("mm@il");
        lblTitulo.setName("lblTitulo"); // NOI18N

        lblCrearCuenta.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        lblCrearCuenta.setText("Crear Cuenta");
        lblCrearCuenta.setName("lblCrearCuenta"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtNombreUsuario.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtNombreUsuario.setName("txtNombreUsuario"); // NOI18N
        jScrollPane1.setViewportView(txtNombreUsuario);

        separadorEstado.setName("separadorEstado"); // NOI18N

        BarraEstado.setEnabled(false);
        BarraEstado.setName("BarraEstado"); // NOI18N

        lblNombreUsuario.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblNombreUsuario.setText("Nombre de Usuario");
        lblNombreUsuario.setName("lblNombreUsuario"); // NOI18N

        lblContraseña.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblContraseña.setText("Contraseña");
        lblContraseña.setName("lblContraseña"); // NOI18N

        txtContraseña.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtContraseña.setName("txtContraseña"); // NOI18N

        txtContraseñare.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtContraseñare.setName("txtContraseñare"); // NOI18N

        lblContraseñaRE.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblContraseñaRE.setText("ReContraseña");
        lblContraseñaRE.setName("lblContraseñaRE"); // NOI18N

        jButton1.setText("Crear Cuenta");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lblDominio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblDominio.setText("@mmail.com.uy");
        lblDominio.setName("lblDominio"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addComponent(lblTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(113, 113, 113))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BarraEstado, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(separadorEstado, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(87, 87, 87)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDominio, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtContraseñare, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addComponent(lblContraseñaRE, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addComponent(txtContraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                        .addGap(45, 45, 45))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblCrearCuenta)
                        .addGap(39, 39, 39))
                    .addComponent(lblNombreUsuario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addComponent(lblContraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE))
                .addGap(84, 84, 84))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTitulo)
                .addGap(18, 18, 18)
                .addComponent(lblCrearCuenta)
                .addGap(33, 33, 33)
                .addComponent(lblNombreUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblDominio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(lblContraseña)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblContraseñaRE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtContraseñare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(separadorEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BarraEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String contraseña = "";
        String contraseñare = "";
        for (int i = 0; i < txtContraseña.getPassword().length; i++) {
            contraseña = contraseña + txtContraseña.getPassword()[i];
            contraseñare = contraseñare + txtContraseñare.getPassword()[i];
        }
        if (contraseña.equals(contraseñare)) {
            try {
                BarraEstado.setText(Controladora.getInstancia().crearCuenta(txtNombreUsuario.getText()+lblDominio.getText(), txtNombreUsuario.getText(), contraseña));
                if(BarraEstado.getText().equals("La cuenta se a creado correctamente")){
                    this.dispose();
                    msnMain.getInstancia().setVisible(true);
                }
            } catch (RemoteException ex) {
                Logger.getLogger(msnCrearCuenta.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NotBoundException ex) {
                Logger.getLogger(msnCrearCuenta.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new msnCrearCuenta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField BarraEstado;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblContraseña;
    private javax.swing.JLabel lblContraseñaRE;
    private javax.swing.JLabel lblCrearCuenta;
    private javax.swing.JLabel lblDominio;
    private javax.swing.JLabel lblNombreUsuario;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JSeparator separadorEstado;
    private javax.swing.JPasswordField txtContraseña;
    private javax.swing.JPasswordField txtContraseñare;
    private javax.swing.JTextPane txtNombreUsuario;
    // End of variables declaration//GEN-END:variables
}
